/**
 * 昵称生成器
 */

export class NicknameGenerator {
  private static readonly zhPrefix = [
    "小",
    "阿",
    "老",
    "大",
    "酷",
    "萌",
    "闪",
    "狂",
    "神",
    "魔",
    "妖",
    "灵",
    "仙",
    "幻",
    "影",
    "夜",
    "风",
    "天",
    "孤",
    "冷",
  ];

  private static readonly zhNames = [
    "明",
    "强",
    "飞",
    "杰",
    "浩",
    "磊",
    "龙",
    "虎",
    "雨",
    "雪",
    "星",
    "月",
    "宇",
    "轩",
    "晨",
    "昊",
    "辰",
    "阳",
    "枫",
    "凡",
  ];

  private static readonly zhSuffix = [
    "哥",
    "仔",
    "酱",
    "君",
    "王",
    "侠",
    "喵",
    "哒",
    "神",
    "仙",
    "尊",
    "主",
    "客",
    "使",
    "者",
    "少",
    "子",
    "生",
    "夫",
    "翁",
  ];

  private static readonly zhExtra = [
    "酱",
    "大人",
    "酱酱",
    "小宝",
    "小萌",
    "小仙",
    "小魔",
    "小影",
    "小星",
    "小月",
    "大大",
    "狂狂",
    "宝宝",
    "喵喵",
    "仔仔",
  ];

  private static readonly enPrefix = [
    "Cool",
    "Cute",
    "Mega",
    "Ultra",
    "Dark",
    "Shadow",
    "Fire",
    "Light",
    "Neo",
    "Cyber",
    "Quantum",
    "Hyper",
    "Solar",
    "Nova",
    "Dr.",
    "Captain",
    "Lord",
    "Master",
    "Sir",
    "Agent",
    "Cyber",
    "DarkLord",
  ];

  private static readonly enNames = [
    "Tom",
    "Jerry",
    "Jack",
    "Max",
    "Leo",
    "Luke",
    "Alex",
    "Zane",
    "Ethan",
    "X",
    "Alpha",
    "Omega",
    "Delta",
    "Echo",
    "Foxy",
    "Blitz",
    "Rex",
    "Byte",
  ];

  private static readonly enSuffix = [
    ".xX",
    ".XX",
    "Pro",
    "Master",
    "Gamer",
    "King",
    "God",
    "X",
    "VIP",
    "Noob",
    "Pro",
    "G",
    "L",
    "GG",
    "XP",
    "Dev",
    "Hacker",
  ];

  private static readonly enExtra = [
    "Elite",
    "PvP",
    "PvE",
    "King",
    "God",
    "GodX",
    "Slayer",
    "Hunter",
    "Warrior",
    "Mage",
    "Archer",
    "Ninja",
    "Samurai",
    "Rogue",
  ];

  /**
   * 生成一个随机昵称
   * @param lang 'zh' 或 'en'
   * @returns string
   */
  public static generateOnce(lang: "zh" | "en"): string {
    if (lang === "zh") {
      return this.generateZhName();
    } else {
      return this.generateEnName();
    }
  }

  private static generateZhName(): string {
    const parts = [];
    if (Math.random() < 0.8) parts.push(this.randomItem(this.zhPrefix));
    parts.push(this.randomItem(this.zhNames));
    if (Math.random() < 0.6) parts.push(this.randomItem(this.zhSuffix));
    if (Math.random() < 0.3) parts.push(this.randomItem(this.zhExtra));
    return parts.join("");
  }

  private static generateEnName(): string {
    const parts = [];
    if (Math.random() < 0.7) parts.push(this.randomItem(this.enPrefix));
    parts.push(this.randomItem(this.enNames));
    if (Math.random() < 0.5) parts.push(this.randomItem(this.enSuffix));
    if (Math.random() < 0.2) parts.push(this.randomItem(this.enExtra));
    return parts.join("");
  }

  private static randomItem<T>(arr: T[]): T {
    return arr[Math.floor(Math.random() * arr.length)];
  }
}
